﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace BillingSystem
{
    /// <summary> Диалог редактирования тарифной информации </summary>
    public partial class FormEditTariff : Form, IDialog
    {
        public FormEditTariff()
        {
            InitializeComponent();
        }

        /// <summary> Показ диалога </summary>
        /// <param name="bs"></param>
        /// <returns></returns>
        public bool ShowForm(BindingSource bs)
        {
            DataRowView drv = (DataRowView)bs.Current;

            if (drv.IsNew)
            {
                drv["TARIFF_ID"] = 0;
                drv["NAME"] = 0;
                this.Text = "Добавление нового тарифа";
            }
            else
            {
                this.Text = "Редактирование информации о тарифе";
            }

            this.textBoxTariffName.DataBindings.Add("Text", drv, "NAME", false,
                DataSourceUpdateMode.OnValidation);

            if (this.ShowDialog() == DialogResult.OK)
            {
                if (textBoxTariffName.Text == "")
                {
                    drv.CancelEdit();
                    return false;
                }
                drv.EndEdit();
                return true;
            }
            return false;
        }
    }
}
